<?php

// +----------------------------------------------------------------------
// | yiran [ 张依然 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018 http://yzncms.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 张依然 <530765310@qq.com>
// +----------------------------------------------------------------------

namespace app\Payment\model;


use think\Model;

class PayAccount extends Model
{
    public function updateOrderData($where,$data)
    {
     $bool=  $this->where($where)
            ->data($data)
            ->update();

       return $bool;
    }

    public function get_one($where){
        $list = $this->where($where)
            ->find();
        if($list){
            $list= $list->toArray();
        }
        return $list;
    }
    public function addData($data){
        if (!is_array($data)) {
            return false;
        }

        return self::create($data, true);
    }
    public function get_page_list($where,$data,$order=['addtime'=>'desc']){

        if($data['start_addtime'] && $data['end_addtime']){

            $list = $this->where($where)
                ->whereTime('addtime', '>=', $data['start_addtime'])
                ->whereTime('addtime', '<=', $data['end_addtime'])
                ->order($order)
                ->paginate($data['limit'])

                ->each(function($item, $key){
                    $item['addtime'] =empty($item['addtime'])?'--':date('Y-m-d H:i:s', $item['addtime']);
                    $item['paytime'] =empty($item['paytime'])?'--':date('Y-m-d H:i:s', $item['paytime']);
                    $item['type'] = $item['type']==1?'金钱':'积分';
                    return $item;
                });
        }else{
            $list =  $this->where($where)
                ->order($order)
                ->paginate($data['limit'])

                ->each(function($item, $key){
                    $item['addtime'] =empty($item['addtime'])?'--':date('Y-m-d H:i:s', $item['addtime']);
                    $item['paytime'] =empty($item['paytime'])?'--':date('Y-m-d H:i:s', $item['paytime']);
                    $item['type'] = $item['type']==1?'金钱':'积分';
                    return $item;
                });
        }

        if($list){
            $list= $list->toArray();
        }
        return $list;
    }
}